package com.yanqu.road.server.cmd.activity.jiuzhou.cross;

import com.yanqu.road.entity.activity.ActivityRewardResult;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.jiuzhou.CrossJiuZhouProto;
import com.yanqu.road.pb.activity.jiuzhou.JiuZhouProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.ActivityModule;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_JIU_ZHOU_GET_RANK_REWARD_FROM_CROSS,desc = "九州棋局跨服获取榜单奖励返回")
public class JiuZhouGetRankRewardFromCrossCmd extends AbstractCommand {
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {


        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        CrossJiuZhouProto.CrossJiuZhouGetRankRewardRespMsg respMsg = CrossJiuZhouProto.CrossJiuZhouGetRankRewardRespMsg.parseFrom(packet.getBytes());
        ActivityRewardResult rewardResult = player.getModule(ActivityModule.class).getCrossRankActivityReward(
                respMsg.getActivityId(),
                respMsg.getConditionId(),
                true,
                respMsg.getRank()
        );
        ret = rewardResult.getRet();
        if (ret != 0){
            return;
        }
        JiuZhouProto.JiuZhouGetRankRewardRespMsg.Builder builder = JiuZhouProto.JiuZhouGetRankRewardRespMsg.newBuilder();
        builder.setRet(0);
        builder.setReward(rewardResult.getReward());
        player.sendPacket(ClientProtocol.U_JIU_ZHOU_GET_RANK_REWARD,builder);

    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0){
            JiuZhouProto.JiuZhouGetRankRewardRespMsg.Builder builder = JiuZhouProto.JiuZhouGetRankRewardRespMsg.newBuilder();
            builder.setRet(ret);
            player.sendPacket(ClientProtocol.U_JIU_ZHOU_GET_RANK_REWARD,builder);
        }
    }
}
